var app = getApp()
Component({
  properties: {
      liveList: {
        type:Array,
        value:[
          {imgShow:false}
        ],
      },
      showTitle:{
        type:Boolean,
        value:true
      },
      showIndex:{
        type:Number,
        value:0,
        observer:'listChange'
      },
      zIndex:{
        type:Boolean,
        value:true
      },
      scale:{
        type:Number,
        value:1,
      },
  },
  data: {
    liveList: []
  },
  ready() {
	  console.log('直播的数据');
	  console.log(this.data.liveList);
    var that = this;
    this._liveList = []
    this.properties.liveList.forEach(item=>{
      item.imgShow = false;
    })
    this.setData({
      liveList:this.properties.liveList
    },()=>{
      setTimeout(() => {
        that.videocom1 = wx.createVideoContext('video0', that)
        this.videocom1.id = 'video0'
        that.videocom2 = wx.createVideoContext('video1', that)
        this.videocom2.id = 'video1'
        that.videocom3 = wx.createVideoContext('video2', that)
        this.videocom3.id = 'video2'
        that.videocom4 = wx.createVideoContext('video3', that)
        this.videocom4.id = 'video3'
        that.calculate()
      }, 1000);
    })
  },
  methods: {
      //商品详情
      liveDetail(e) {
        var id = e.currentTarget.dataset.id;
        var p = e.currentTarget.dataset.p;
        var index = e.currentTarget.dataset.index;
        app.globalData.cur_product = this.data.liveList[index];
         商品详情页面
        wx.navigateTo({
            url: '/pages/module/productDetail/productDetail?id=' + id + '&p=' + p,
        })
        
         /*wx.navigateTo({
             url: '/pages/module/liveDetail/liveDetail?id=' + id,
         })
*/
        
      },
      videoChange(e){
        if(!this.videocom1) return;
        if(e.currentTarget.id == this.videocom1.id || e.currentTarget.id == this.videocom2.id){
          if(e.detail.currentTime>=7){
            this.videocom1.seek(0)
            this.videocom2.seek(0)
            if(!this.videocom3) return;
            this.videocom3.seek(0)
            this.videocom4.seek(0)
          }
        }
      },
      listChange(e){
        var that = this;
        this.setData({
          zIndex:false
        })
        var text1 = 'video' + (e * 2 + 0)
        this.videocom1 = wx.createVideoContext(text1, that)
        this.videocom1.id = text1
        var text2 = 'video' + (e * 2 + 1)
        this.videocom2 = wx.createVideoContext(text2, that)
        this.videocom2.id = text2
      },
      moreLive(){
        wx.switchTab({
            url: '/pages/tabbar/live/live',
        })
      },
      calculate(){
        var that = this;
        const query = wx.createSelectorQuery().in(this);
        query.select('#videocom0').boundingClientRect();
        query.exec((res) => {
          that.triggerEvent('videoInfo', {res: res});
        });
      },
      imgLoad(e){
        var index = e.currentTarget.dataset.index;
        this.data.liveList[index].imgShow=true;
        this.setData({
          liveList:this.data.liveList
        })
      },
  },
})